package com.lecampus.businessCampus_moments.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lecampus.businessCampus_moments.entity.ArticleLabel;
import com.lecampus.businessCampus_moments.mapper.ArticleLabelMapper;
import com.lecampus.businessCampus_moments.service.ArticleLabelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lecampus.businessCampus_moments.vo.ArticleLabelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-10
 */
@Service
public class ArticleLabelServiceImpl extends ServiceImpl<ArticleLabelMapper, ArticleLabel> implements ArticleLabelService {

    @Autowired
    private ArticleLabelMapper articleLabelMapper;

    private ArticleLabelVO labelVO;
    private List<ArticleLabel> articleLabelList;
    private List<ArticleLabelVO> articleLabelVOList;

    @Override
    public List<ArticleLabelVO> findAllLabel() {
        QueryWrapper<ArticleLabel> wrapper = new QueryWrapper<>();
        articleLabelList = articleLabelMapper.selectList(wrapper);

        articleLabelVOList = new ArrayList<>();

        for (ArticleLabel articleLabel : articleLabelList) {
            //封装 LabelDataVO
            labelVO = new ArticleLabelVO();

            BeanUtils.copyProperties(articleLabel,labelVO);

            articleLabelVOList.add(labelVO);
        }

        return articleLabelVOList;
    }
}